import type { PageParam, PageResult } from '#/api/base';

import { requestClient } from '#/api/request';

export namespace ApiApi {
  /** API信息 */
  export interface Api {
    id?: number;
    systemId: number;
    title: string;
    path: string;
    handler: number;
    handlerName: string;
    createTime: string;
    updateTime: string;
  }
}

/** 查询API列表 */
export function getApiList(params: PageParam & { systemId: number }) {
  return requestClient.get<PageResult<ApiApi.Api>>('/api/list', {
    params,
  });
}

/** 获取API详情 */
export function getApi(id: number) {
  return requestClient.get<ApiApi.Api>(`/api/info?id=${id}`);
}

/** 创建API */
export function createApi(data: ApiApi.Api) {
  return requestClient.post<ApiApi.Api>('/api/create', data);
}

/** 更新API */
export function updateApi(data: ApiApi.Api) {
  return requestClient.put<ApiApi.Api>(`/api/update`, data);
}

/** 删除API */
export function deleteApi(id: number) {
  return requestClient.delete(`/api/delete?id=${id}`);
}
